package com.settlement.system.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 抖音订单
 * </p>
 *
 * @author huangrensen
 * @since 2023-08-05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DyOrder extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;


    private String mainOrderNo;


    private String subOrderNo;


    private String buyProduct;


    private String specifications;


    private Integer quantity;


    private String productId;


    private String businessCode;


    private BigDecimal productPrice = BigDecimal.ZERO;


    private BigDecimal payAmount = BigDecimal.ZERO;


    private BigDecimal transportFee = BigDecimal.ZERO;


    private BigDecimal preferentialAmout = BigDecimal.ZERO;


    private String preformPreferential;


    private String businessPreferential;


    private String drPreferential;


    private BigDecimal modifyPrice = BigDecimal.ZERO;


    private BigDecimal payPreferential = BigDecimal.ZERO;


    private BigDecimal deduction = BigDecimal.ZERO;


    private String payType;


    private BigDecimal handlingFee = BigDecimal.ZERO;


    private String receiver;


    private String receiverPhone;


    private String provice;


    private String city;


    private String area;


    private String street;


    private String address;


    private String modifyAddress;


    private String buyerRemark;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderTime;


    private String flagColor;


    private String sellerRemark;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderFinishTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime payFinishTime;


    private String appChannel;


    private String source;


    private String orderStatus;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime promiseSendTime;


    private String orderType;


    private String lbldyId;


    private String drId;


    private String drNickName;


    private String ownerShopId;


    private String serviceStatus;


    private String rejectReason;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime previousSendTime;

    private String peaceBuy;


    private String adviceChannel;


    private String flowType;


    private String flowApp;


    private String flowChannel;


    private String senderCompany;


    private String senderCompanyDetail;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;


    private BigDecimal cutPrice = BigDecimal.ZERO;


    private BigDecimal preformPreferentialPrice = BigDecimal.ZERO;


    private BigDecimal sellerPreferentialPrice = BigDecimal.ZERO;


    private BigDecimal drPreferentialPrice = BigDecimal.ZERO;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime previousReceiveTime;


    private String preformFlow;


    private String vehicle;


    private Long createBy;


    private Long updateBy;

    @TableField(exist = false)
    private String tableName;

    // 所属平台
    private String platform;

    // 登录账号
    private String userName;

    // 店铺ID
    private Long storeId;

    // 店铺名称
    private String storeName;

    // 关联核销单号
    private String auditNo;

    // 账单月份
    private String billMonth;

    public static boolean isDate(String field) {
        return "orderTime,orderFinishTime,payFinishTime,promiseSendTime,previousSendTime,sendTime,previousReceiveTime".contains(field);
    }

    public static boolean isDecimal(String field) {
        return "productPrice,payAmount,transportFee,preferentialAmout,modifyPrice,payPreferential,deduction,handlingFee,cutPrice,preformPreferentialPrice,sellerPreferentialPrice,drPreferentialPrice".contains(field);
    }

    public static boolean isInteger(String field) {
        return "quantity".contains(field);
    }

    private static boolean compareDate(LocalDateTime date1, LocalDateTime date2) {
        if (date1 == null && date2 == null) {
            return true;
        }
        if (date1 != null && date1.equals(date2)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        DyOrder dyOrder = (DyOrder) o;
        return Objects.equals(mainOrderNo, dyOrder.mainOrderNo) && Objects.equals(subOrderNo, dyOrder.subOrderNo) && Objects.equals(buyProduct, dyOrder.buyProduct) && Objects.equals(specifications, dyOrder.specifications) && Objects.equals(quantity, dyOrder.quantity) && Objects.equals(productId, dyOrder.productId) && Objects.equals(businessCode, dyOrder.businessCode) && productPrice.compareTo(dyOrder.productPrice) == 0 && payAmount.compareTo(dyOrder.payAmount) == 0 && transportFee.compareTo(dyOrder.transportFee) == 0 && preferentialAmout.compareTo(dyOrder.preferentialAmout) == 0 && Objects.equals(preformPreferential, dyOrder.preformPreferential) && Objects.equals(businessPreferential, dyOrder.businessPreferential) && Objects.equals(drPreferential, dyOrder.drPreferential) && modifyPrice.compareTo(dyOrder.modifyPrice) == 0 && payPreferential.compareTo(dyOrder.payPreferential) == 0 && deduction.compareTo(dyOrder.deduction) == 0 && Objects.equals(payType, dyOrder.payType) && handlingFee.compareTo(dyOrder.handlingFee) == 0 && Objects.equals(receiver, dyOrder.receiver) && Objects.equals(receiverPhone, dyOrder.receiverPhone) && Objects.equals(provice, dyOrder.provice) && Objects.equals(city, dyOrder.city) && Objects.equals(area, dyOrder.area) && Objects.equals(street, dyOrder.street) && Objects.equals(address, dyOrder.address) && Objects.equals(modifyAddress, dyOrder.modifyAddress) && Objects.equals(buyerRemark, dyOrder.buyerRemark) && compareDate(orderTime, dyOrder.orderTime) && Objects.equals(flagColor, dyOrder.flagColor) && Objects.equals(sellerRemark, dyOrder.sellerRemark) && compareDate(orderFinishTime, dyOrder.orderFinishTime) && compareDate(payFinishTime, dyOrder.payFinishTime) && Objects.equals(appChannel, dyOrder.appChannel) && Objects.equals(source, dyOrder.source) && Objects.equals(orderStatus, dyOrder.orderStatus) && compareDate(promiseSendTime, dyOrder.promiseSendTime) && Objects.equals(orderType, dyOrder.orderType) && Objects.equals(lbldyId, dyOrder.lbldyId) && Objects.equals(drId, dyOrder.drId) && Objects.equals(drNickName, dyOrder.drNickName) && Objects.equals(ownerShopId, dyOrder.ownerShopId) && Objects.equals(serviceStatus, dyOrder.serviceStatus) && Objects.equals(rejectReason, dyOrder.rejectReason) && compareDate(previousSendTime, dyOrder.previousSendTime) && Objects.equals(peaceBuy, dyOrder.peaceBuy) && Objects.equals(adviceChannel, dyOrder.adviceChannel) && Objects.equals(flowType, dyOrder.flowType) && Objects.equals(flowApp, dyOrder.flowApp) && Objects.equals(flowChannel, dyOrder.flowChannel) && Objects.equals(senderCompany, dyOrder.senderCompany) && Objects.equals(senderCompanyDetail, dyOrder.senderCompanyDetail) && compareDate(sendTime, dyOrder.sendTime) && cutPrice.compareTo(dyOrder.cutPrice) == 0 && preformPreferentialPrice.compareTo(dyOrder.preformPreferentialPrice) == 0 && sellerPreferentialPrice.compareTo(dyOrder.sellerPreferentialPrice) == 0 && drPreferentialPrice.compareTo(dyOrder.drPreferentialPrice) == 0 && compareDate(previousReceiveTime, dyOrder.previousReceiveTime) && Objects.equals(preformFlow, dyOrder.preformFlow) && Objects.equals(vehicle, dyOrder.vehicle) && Objects.equals(platform, dyOrder.platform) && Objects.equals(userName, dyOrder.userName) && Objects.equals(storeId, dyOrder.storeId) && Objects.equals(storeName, dyOrder.storeName);
    }

    @Override
    public int hashCode() {
        return Objects.hash(mainOrderNo, subOrderNo, buyProduct, specifications, quantity, productId, businessCode, productPrice, payAmount, transportFee, preferentialAmout, preformPreferential, businessPreferential, drPreferential, modifyPrice, payPreferential, deduction, payType, handlingFee, receiver, receiverPhone, provice, city, area, street, address, modifyAddress, buyerRemark, orderTime, flagColor, sellerRemark, orderFinishTime, payFinishTime, appChannel, source, orderStatus, promiseSendTime, orderType, lbldyId, drId, drNickName, ownerShopId, serviceStatus, rejectReason, previousSendTime, peaceBuy, adviceChannel, flowType, flowApp, flowChannel, senderCompany, senderCompanyDetail, sendTime, cutPrice, preformPreferentialPrice, sellerPreferentialPrice, drPreferentialPrice, previousReceiveTime, preformFlow, vehicle, platform, userName, storeId, storeName);
    }
}
